|
|
|
| |
EJB 2.0 for BEA WebLogic Server Container Services
Locking and Caching Services for Entity EJBs
In-memory Replication for Stateful Session EJBs
Requirements and Configuration
Home Method Support for Entity EJBs
This section describes the new and changed services available with the EJB 2.0 for BEA WebLogic Server container. The information in this section supplements the EJB 1.1 container information in The WebLogic Server EJB Container.
Locking and Caching Services for Entity EJBs
The EJB 1.1 container in WebLogic Server Version 5.1 uses a pessimistic locking mechanism for entity EJB instances. As clients enlist an EJB or EJB method in a transaction, WebLogic Server places an exclusive lock on the EJB instance or method for the duration of the transaction. Other clients requesting the same EJB or method block until the current transaction completes.
This method of locking provides reliable access to EJB data, and avoids unnecessary calls to ejbLoad() to refresh the EJB instance's persistent fields. However, pessimistic locking does not provide the best model for concurrent access to the EJB's data. Once a client has locked an EJB instance, other clients are blocked from the EJB's data even if they intend only to read the persistent fields.
To improve concurrent access for entity EJB's, the WebLogic Server EJB 2.0 container enables you to defer locking services to the underlying database. In most cases, the underlying data store can provide finer granularity for locking EJB data (as well as provide deadlock detection), and improve throughput for concurrent access to the bean's data.
Database locking services
With the database locking mechanism of the EJB 2.0 container, WebLogic Server continues to cache instances of entity EJB classes. However, the container does not cache the intermediate state of the EJB instance between transactions. Instead, WebLogic Server calls ejbLoad() for each instance at the beginning of a transaction to obtain the latest EJB data. The request to commit data is subsequently passed along to the database. The database, therefore, handles all lock management and deadlock detection for the EJB's data.
Deferring locks to the underlying database provides an easy way to improve throughput for concurrent access to entity EJB data, while also providing deadlock detection. However, using database locking requires more detailed knowledge of the underlying datastore's lock policies, which can reduce the EJB's portability among different systems.
Setting up database locking
The deployer specifies the locking mechanism to use for an EJB by setting the concurrency-strategy deployment parameter in weblogic-ejb-jar.xml. concurrency-strategy is set at the individual EJB level, so that you can mix locking mechanisms within the EJB 2.0 container.
The following excerpt from weblogic-ejb-jar.xml shows an EJB that uses database locking:
<entity-descriptor>
<entity-cache>
...
<concurrency-strategy>Database</concurrency-strategy>
</entity-cache>
...
</entity-descriptor>
If you do not specify concurrency-strategy, WebLogic Server performs exclusive locking for entity EJB instances, as described in Locking and Caching Services for Entity EJBs.
In-memory Replication for Stateful Session EJBs
The WebLogic Server EJB 2.0 container introduces new clustering support for stateful session EJBs. Whereas in Version 5.1 only the EJBHome is clustered for stateful session EJBs, the EJB 2.0 container can also replicate the state of the EJB across clustered WebLogic Server instances.
Replication support for stateful session EJBs is transparent to clients of the EJB. When a stateful session EJB is deployed, WebLogic Server creates a cluster-aware EJBHome stub and a replica-aware EJBObject stub for the stateful session EJB. The EJBObject stub maintains a list of the primary WebLogic Server instance on which the EJB instance runs, as well as the name of a secondary WebLogic Server to use for replicating the bean's state.
Each time a client of the EJB commits a transaction that modifies the EJB's state, WebLogic Server replicates the bean's state to the secondary server instance. Replication of the bean's state occurs directly in memory, for best performance in a clustered environment.
Should the primary server instance fail, the client's next method invocation is automatically transferred to the EJB instance on the secondary server. The secondary server becomes the primary WebLogic Server for the EJB instance, and a new secondary server is used to account for the possibility of additional failovers. Should the EJB's secondary server fail, WebLogic Server creates enlists a new secondary server instance from the cluster.
Clients of a stateful session EJB are therefore guaranteed to have quick access to the latest committed state of the EJB, except under the special circumstances described in Limitations below.
Requirements and Configuration
To replicate the state of a stateful session EJB in a WebLogic Server cluster, you must ensure that the cluster is homogeneous for the EJB class. In other words, you must deploy the same EJB class to every WebLogic Server instance in the cluster, using the same deployment properties. In-memory replication is not supported for heterogeneous clusters.
By default, WebLogic Server does not replicate the state of stateful session EJB instances in a cluster. This models the behavior released with WebLogic Server Version 5.1. To enable replication, set the replication-type deployment parameter to InMemory in the weblogic-ejb-jar.xml deployment file. For example:
<stateful-session-clustering>
...
<replication-type>InMemory</replication-type>
</stateful-session-clustering>
Limitations
By replicating the state of a stateful session EJB, clients are generally guaranteed to have the last committed state of the EJB, even if the primary WebLogic Server instance fails. However, in certain rare failover scenarios, the last committed state may not be available. This can happen when:
The EJB 2.0 container provides new support for entity EJB home methods. Home methods provide an easy way to perform business logic that does not require access to an actual instance of an EJB. For example, using home methods you can query for supporting data immediately after obtaining the home interface for an EJB (but before using a finder to obtain EJB instances).
The EJB 2.0 specification provides few restrictions on developing and using entity EJB home methods. Each home method must throw java.rmi.RemoteException, and its method signature must not resemble a finder method or instance method. (For example, the method cannot begin with find, create, or remove, since those signatures are reserved for working with the EJB instance). Within these restrictions, you can perform any business logic that does not involve the EJB instance.
|
|
|
Copyright © 2000 BEA Systems, Inc. All rights reserved.
|